<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>

    var i = 20

    function fn() {
        i -= 2
        return function (n) {
            console.log(++i - n)
        }
    }

    var f = fn()                    // 18

    f(1)                            // 19, >>18
    f(2)                            // 20, >>18
    fn()(3)                         // 19, >>16
    fn()(4)                         // 18, >>14
    f(5)                            // 19, >>14
    console.log(i)                  // >> 19

</script>
</body>
</html>